﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeStash.Addin.Core;
using CodeStash.Addin.ViewModels;
using CodeStash.Common.Enums;

namespace CodeStash.Addin
{
    public class SearchViewModelValidator : Validator
    {
        private SearchViewModel vm;

        public SearchViewModelValidator(SearchViewModel vm)
        {
            this.vm = vm;
            this.EntityError = "SearchViewModel has errors";
        }


        private void ValidateKeyWord()
        {
            if (string.IsNullOrEmpty(vm.KeyWord))
            {
                ValidationFailure("KeyWord", "You need to select a KeyWord filter");
            }
        }

        private void ValidateLanguage()
        {
            if (vm.SelectedLanguage == null)
            {
                ValidationFailure("SelectedLanguage", "You need to select a Language filter");
            }
        }

        private void ValidateTags()
        {
            if (string.IsNullOrEmpty(vm.Tags))
            {
                ValidationFailure("Tags", "You need to select a Tags filter");
            }
        }

        protected override void ValidateOverride()
        {
            switch (vm.SelectedSearchType)
            {
                case SearchType.ByKeyWord:
                    ValidateKeyWord();
                    break;
                case SearchType.ByLanguage:
                    ValidateLanguage();
                    break;
                case SearchType.ByTag:
                    ValidateTags();
                    break;
            }

            if (((int)vm.SelectedVisibility) == 0)
            {
                ValidationFailure("SelectedVisibility", "You need to select a Visibility filter");
            }
            
        }


    }
}
